package com.sskj.mine.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bulong.rudeness.RudenessScreenHelper;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.mvchelper.ModelRx2DataSource;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.asset.data.ExchangeRecordsBean;
import com.sskj.mine.presenter.ExchangeRecordsPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 划转记录
 */
@Route(path = RConfig.MINE_EXCHANGE_RECORD)
public class ExchangeRecordsActivity extends BaseActivity<ExchangeRecordsPresenter> {

    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.coolRefreshView)
    CoolRefreshView coolRefreshView;
    private SlimAdapter slimAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.mine_activity_exchange_records;
    }

    @Override
    public ExchangeRecordsPresenter getPresenter() {
        return new ExchangeRecordsPresenter();
    }

    @Override
    public void initView() {
        setTitle(App.INSTANCE.getString(R.string.mine_exchangeRecordsActivity1));
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setFirstDraw(false)
                .setLastDraw(false)
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 20))
                .setDividerColor(color(R.color.transparent)));
        slimAdapter = SlimAdapter.create().register(R.layout.mine_item_exchange, new SlimInjector<ExchangeRecordsBean>() {
            @Override
            public void onInject(ExchangeRecordsBean data, IViewInjector injector, List<Object> list) {
                injector
                        .text(R.id.tvNum, data.getRotationNum()+data.getCode())
                        .text(R.id.tvTime, data.getCreated_at())
                        .text(R.id.tvAccount, data.getMemo())
                ;

            }

        });
        slimAdapter.attachTo(recyclerView).updateData(new ArrayList());

        ModelRx2DataSource<ExchangeRecordsBean> dataSource = new ModelRx2DataSource<>((ModelRx2DataSource.OnLoadSource<ExchangeRecordsBean>)
                page -> mPresenter.getCashRecord(page + "", "20"), 20);
        MVCCoolHelper<List<ExchangeRecordsBean>> mvcHelper = new MVCCoolHelper<>(coolRefreshView);
        mvcHelper.setDataSource(dataSource);
        mvcHelper.setAdapter(slimAdapter);
        mvcHelper.refresh();
    }

    @Override
    public void initData() {

    }

    public static void start(Context context) {
        Intent intent = new Intent(context, ExchangeRecordsActivity.class);
        context.startActivity(intent);
    }

}
